package com.michaelbulava.TFS.vcs.utils;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.actions.VcsContextFactory;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.RefreshQueue;
import com.intellij.ui.GuiUtils;
import com.intellij.util.PlatformUtils;
import com.intellij.util.ThreeState;
import com.intellij.util.io.ReadOnlyAttributeUtil;
import com.intellij.vcsUtil.VcsUtil;
import com.michaelbulava.TFS.TFSVcsModuleComponent;
import com.michaelbulava.TFS.log.FileLogger;
import com.michaelbulava.TFS.persistence.IdeaPersistenceStoreProvider;
import com.michaelbulava.TFS.tasks.connect.ConnectToCollectionTask;
import com.michaelbulava.TFS.tasks.workspaces.QueryLocalWorkspacesTask;
import com.michaelbulava.TFS.vcs.TFSVcs;
import com.michaelbulava.TFS.vcs.exceptions.TFSException;
import com.michaelbulava.TFS.vcs.internal.TFSFiles.TFSFilePath;
import com.microsoft.tfs.core.TFSTeamProjectCollection;
import com.microsoft.tfs.core.clients.versioncontrol.GetItemsOptions;
import com.microsoft.tfs.core.clients.versioncontrol.GetOptions;
import com.microsoft.tfs.core.clients.versioncontrol.Workstation;
import com.microsoft.tfs.core.clients.versioncontrol.path.ServerPath;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.*;
import com.microsoft.tfs.core.clients.versioncontrol.specs.ItemSpec;
import com.microsoft.tfs.core.clients.versioncontrol.specs.version.VersionSpec;
import com.microsoft.tfs.core.clients.versioncontrol.workspacecache.WorkspaceInfo;
import com.microsoft.tfs.jni.PlatformMisc;
import com.microsoft.tfs.jni.PlatformMiscUtils;
import com.microsoft.tfs.util.Check;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

/**
 * Created by mbulava on 5/7/2015.
 */
public class TFSFileUtil {
    private static final Logger log = FileLogger.getInstance(TFSFileUtil.class);

    public static void setReadonly(final VirtualFile file, final boolean readonly) throws IOException {
        setReadonly(Collections.singletonList(file), readonly);
    }

    public static void setReadonly(final Collection<VirtualFile> files, final boolean readOnly) throws IOException{
        final Ref<IOException> exceptionRef = new Ref<>();
        try{
            GuiUtils.runOrInvokeAndWait(new Runnable() {
                @Override
                public void run() {
                    ApplicationManager.getApplication().runWriteAction(new Runnable() {
                        @Override
                        public void run() {
                            try{
                                for(VirtualFile file : files)
                                    ReadOnlyAttributeUtil.setReadOnlyAttribute(file, readOnly);
                            } catch (IOException e) {
                                exceptionRef.set(e);
                            }
                        }
                    });
                }
            });
        } catch (InterruptedException e) {
        } catch (InvocationTargetException e) {
        }
        if (!exceptionRef.isNull())
            throw exceptionRef.get();
    }

    private static void setReadonly(final String path, final boolean readOnly) throws IOException {
        final Ref<IOException> exceptionRef = new Ref<IOException>();
        try{
            GuiUtils.runOrInvokeAndWait(new Runnable() {
                @Override
                public void run() {
                    try{
                        ReadOnlyAttributeUtil.setReadOnlyAttribute(path, readOnly);
                    } catch (IOException e) {
                        exceptionRef.set(e);
                    }
                }
            });
        } catch (InterruptedException e) {
        } catch (InvocationTargetException e) {
        }
        if (!exceptionRef.isNull()){
            throw exceptionRef.get();
        }
    }

    public static void setReadonly(final List<FilePath> files, final boolean readonly) throws IOException{
        setReadonly(toVirtualFiles(files), readonly);
    }


    public static FilePath getFilePath(VirtualFile f){
        if (f == null)
            throw new IllegalArgumentException("f cannot be null");
        return VcsContextFactory.SERVICE.getInstance().createFilePathOn(f);
    }

    public static FilePath getFilePath(Workspace workspace, ExtendedItem item){
//        Check.notNull(workspace, "workspace");
//        Check.notNull(item, "item");
//        String filePath = item.getLocalItem();
//
//        if (filePath == null){
//            //If the filePath it null the file most likely doesn't exist locally
//            //So let TFS translate from Server to local path
//            PathTranslation translatedPath = workspace
//                    .translateServerPathToLocalPath(item.getTargetServerItem());
//            filePath = translatedPath.getTranslatedPath();
//        }
//        return getFilePath(filePath, item.getItemType() == ItemType.FOLDER);
        return new TFSFilePath(workspace, item);

    }

    public static FilePath getFilePath(String path, boolean isDirectory){
        File file = new File(path);
        //return VcsContextFactory.SERVICE.getInstance().createFilePathOnNonLocal(path, isDirectory);
        return VcsContextFactory.SERVICE.getInstance().createFilePathOn(file, isDirectory);
    }

    public static FilePath getFilePath(Item item, Workspace workspace){
        PathTranslation pathTranslation = workspace.translateServerPathToLocalPath(item.getServerItem());
        return getFilePath(pathTranslation.getTranslatedPath(), item.getItemType() == ItemType.FOLDER);
    }

    public static List<FilePath> getFilePaths(Collection<VirtualFile> files){
        if (files == null)
            throw new IllegalArgumentException("files is null");
        List<FilePath> paths = new ArrayList<FilePath>();
        for(VirtualFile f : files){
            paths.add(getFilePath(f));
        }
        return paths;
    }

    public static List<FilePath> getFilePaths(VirtualFile[] files){
        return getFilePaths(Arrays.asList(files));
    }

    public static List<FilePath> getFilePaths(String[] filePaths){
        List<FilePath> files  = new ArrayList<FilePath>();
        for (int i = 0; i < filePaths.length;i++){
            files.add(VcsUtil.getFilePath(filePaths[i]));
        }
        return files;
    }

    public static String[] getFilePathStrings(Collection<FilePath> files){
        List<String> paths = new ArrayList<String>();
        for(FilePath file : files){
            paths.add(file.getPath());
        }
        return paths.toArray(new String[paths.size()]);
    }


    public static GetRequest[] getGetRequests(Project project, Workspace workspace, List<FilePath> files,
                                              VersionSpec versionSpec, boolean recursive){
        ItemSpec[] itemSpecs = getItemSpecs(project, workspace, files, recursive, false);
        GetRequest[] requests = new GetRequest[itemSpecs.length];
        for(int i = 0; i < itemSpecs.length; i++){
            requests[i] = new GetRequest(itemSpecs[i], versionSpec);
        }
        return requests;
    }


    public static ItemSpec[] getItemSpecs(Project project, Workspace workspace, List<FilePath> files){
        return getItemSpecs(project, workspace, files, false);
    }

    public static ItemSpec[] getItemSpecs(Project project, Workspace workspace, List<FilePath> files, boolean recursive){
        return getItemSpecs(project, workspace, files, recursive, false);
    }

    public static ItemSpec[] getItemSpecs(Project project, Workspace workspace, List<FilePath> files,  boolean recursive, boolean useServerPath){
        Check.notNull(workspace, "workspace");
        Check.notNull(files, "files");
        List<String> serverPaths = new ArrayList<String>();
        for(FilePath file : files){
            if (!TFSVcs.getInstance(project).isIgnoredFile(file)){
                String localPath = file.getVirtualFile().getPath();
                if (localPath.substring(0, 3).matches("^([A-Z;a-z]{1}):/")) //Windows needs to flip the slash
                    localPath = localPath.replace('/', '\\');
                if (useServerPath){
                    String serverPath = workspace.getMappedServerPath(localPath);
                    if (serverPath == null && file.isDirectory()){
                        WorkingFolder[] folders = workspace.getFolders();
                        for(int i = 0; i < folders.length; i++){
                            FilePath folder = getFilePath(folders[i].getLocalItemRaw(), true);
                            if (folder.equals(file)) {
                                serverPath = folders[i].getServerItem();
                                break;
                            }
                        }
                    }
                    if (serverPath != null)
                        serverPaths.add(serverPath);
                } else {
                    serverPaths.add(localPath);
                }
            }
        }
        return ItemSpec.fromStrings(serverPaths.toArray(new String[0]), recursive ? RecursionType.FULL : RecursionType.NONE);
    }

    public static ItemSpec[] getItemSpec(Project project, Workspace workspace, VirtualFile file){
        List<FilePath> files = new ArrayList<FilePath>();
        files.add(getFilePath(file));
        ItemSpec[] itemSpecs = getItemSpecs(project, workspace, files);
        TFSVcs.assertTrue(itemSpecs.length == 1);
        return itemSpecs;
    }

    public static ItemSpec[] getItemSpec(Project project, Workspace workspace, FilePath file){
        List<FilePath> files = new ArrayList<>();
        files.add(file);
        ItemSpec[] itemSpecs = getItemSpecs(project, workspace, files);
        TFSVcs.assertTrue(itemSpecs.length == 1);
        return itemSpecs;
    }

    public static ItemSpec createItemSpec(String path, RecursionType recursionType){
        return createItemSpec(path, recursionType, 0);
    }

    public static ItemSpec createItemSpec(String path, RecursionType recursionType, int deletedId){
        return new ItemSpec(path, recursionType, deletedId);
    }



    public static boolean localItemExists(FilePath localPath){
        VirtualFile file = localPath.getVirtualFile();
        return (file != null && file.isValid() && file.exists());
    }

    public static List<String> getFileStringPaths(List<FilePath> files) throws IOException {
        List<String> list = new ArrayList<String>();
        for(FilePath file : files){
            list.add(file.getIOFile().getCanonicalPath());
        }
        return list;
    }

    public static boolean isFileWritable(FilePath localPath){
        VirtualFile file = localPath.getVirtualFile();
        if (file == null)
            file = VcsUtil.getVirtualFile(localPath.getPath());

        return (file.isWritable()) && !file.isDirectory();
    }

    public static void setFileContent(File destination, ContentWriter contentWriter) throws IOException{
        if (destination == null)
            throw new IllegalArgumentException("destination is null");
        if (contentWriter == null)
            throw new IllegalArgumentException("contentWriter is null");


        Check.isTrue(!destination.isDirectory(), destination + " expected to be a file");
        OutputStream fileStream = null;
        try{
            if (destination.exists() && !destination.canWrite())
                setReadonly(destination.getPath(), false);
            fileStream = new FileOutputStream(destination);
            contentWriter.write(fileStream);
        } finally{
            if (fileStream != null){
                try{
                    fileStream.close();
                } catch(IOException e){}
            }
        }

    }

//    public static Module getModuleForFile(VirtualFile file){
//        return getModuleForFile(file, getProjectFromFile(file));
//    }

    public static Module getModuleForFile(VirtualFile file, Project project){
        return ModuleUtil.findModuleForFile(file, project);
    }

    public static Module getModuleForFile(FilePath file, Project project){
        if (file.getVirtualFile() != null)
            return getModuleForFile(file.getVirtualFile(), project);
        else{
            if (!TFSVcs.getInstance(project).isIgnoredFile(file)){
                log.debug("Hmm?");
            }
            VirtualFile vFile = null;

            if(file.getIOFile() != null)
            {
                while(vFile == null){
                    vFile = VcsUtil.getVirtualFile(file.getIOFile());
                    if (vFile == null)
                        file = file.getParentPath();
                }
            }


            if (vFile == null && file.getPath() != null)
                vFile = VcsUtil.getVirtualFile(file.getPath());

            if (vFile != null)
                return getModuleForFile(vFile, project);


            return null;
        }
    }

    public static void markDirtyRecursively(final Project project, final Collection<FilePath> roots){
        if (roots.isEmpty())
            return;
        ApplicationManager.getApplication().runReadAction(new Runnable() {
            @Override
            public void run() {
                for (FilePath root : roots) {
                    VcsDirtyScopeManager.getInstance(project).dirDirtyRecursively(root);
                }
            }
        });
    }

    public static void refreshAndInvalidate(Project project, FilePath[] roots, boolean async){
        VirtualFile[] files = new VirtualFile[roots.length];
        for(int i = 0; i < roots.length; i++){
            files[i] = roots[i].getVirtualFile();
        }
        refreshAndMarkDirty(project, files, async);
    }

    public static void refreshAndMarkDirty(final Project project, final VirtualFile[] roots, boolean async){
        RefreshQueue.getInstance().refresh(async, true, new Runnable() {
            @Override
            public void run() {
                for (VirtualFile root : roots) {
                    try {
                        Check.isTrue(root != null);
                        //TFSVcs.assertTrue(root != null);
                        VcsDirtyScopeManager.getInstance(project).dirDirtyRecursively(root);
                    } catch (RuntimeException e) {
                        //TODO
                        //TFSVcs.error(Messages.getString("TFSFileUtil.ErrorInRefresh") + e);
                        throw e;
                    }
                }
            }
        }, roots);
    }

    private static Collection<VirtualFile> toVirtualFiles(Collection<FilePath> files){
        Collection<VirtualFile> newList = new ArrayList<VirtualFile>();
        for(FilePath file : files){
            if (file.getVirtualFile() != null)
                newList.add(file.getVirtualFile());
            else
                newList.add(VcsUtil.getVirtualFile(file.getPath()));
        }
        return newList;
    }

    public static void refreshAndMarkDirty(Project project, Collection<VirtualFile> roots, boolean async){
        refreshAndMarkDirty(project, VfsUtil.toVirtualFileArray(roots), async);
    }

    public static void markFilesDirty(final Project project, final List<FilePath> files){
        ApplicationManager.getApplication().runReadAction(new Runnable() {
            @Override
            public void run() {
                for(FilePath file : files){
                    VcsDirtyScopeManager.getInstance(project).fileDirty(file);
                }
            }
        });
    }



    public static abstract interface ContentWriter{
        public abstract void write(OutputStream outputStream);
    }

    public static Map<FilePath, ExtendedItem> getFilePathExtendedItemMapRecursive(final Project project, final Workspace workspace,
                                                                                  final List<FilePath> localFiles){
        final Map<FilePath, ExtendedItem> result = new HashMap<FilePath, ExtendedItem>();
        Task.Modal task = new Task.Modal(project, "Querying ExtendedItems", false) {
            @Override
            public void run(ProgressIndicator indicator) {
                //indicator.setIndeterminate(false);
                int currentItem = 0;
                int totalItems = localFiles.size();
                ItemSpec[] specs = getItemSpecs(project, workspace, localFiles, true);
                ExtendedItem[][] items = workspace.getExtendedItems(specs, DeletedState.ANY, ItemType.ANY);
                for(int i = 0; i < specs.length; i++){

                    if (i < items.length){
                        for(int j =0; j < items[i].length; j++){
                            FilePath file  = getFilePath(workspace ,items[i][j]);
                            result.put(file, items[i][j]);
                        }
                    }
                }
//                for (FilePath file : localFiles){
//
//                    ExtendedItem[] items = workspace.getExtendedItems(file.getPath(), DeletedState.ANY,
//                            ItemType.ANY);
//                    if (items != null && items.length == 1){
//                        result.put(file, items[0]);
//                    } else {
//                        result.put(file, null);
//                    }
//
//                    currentItem++;
//                    if (currentItem < totalItems){
//                        double fraction = (double)currentItem / (double)totalItems;
//                        indicator.setFraction(fraction);
//                    }
//                }
                //indicator.stop();
            }
        };
        task.run(null);
       //ProgressManager.getInstance().run(task);

        return result;
    }

    public static Map<FilePath, ExtendedItem> getFilePathExtendedItemMap(final Project project, final Workspace workspace,
                                                                         final List<FilePath> localFiles){
        final Map<FilePath, ExtendedItem> result = new HashMap<FilePath, ExtendedItem>();

        Task.Modal task = new Task.Modal(project, "Querying ExtendedItems", false) {
            @Override
            public void run(ProgressIndicator indicator) {
                indicator.setIndeterminate(false);
                int currentItem = 0;
                int totalItems = localFiles.size();
                ItemSpec[] specs = getItemSpecs(project, workspace, localFiles, true);
                for (FilePath file : localFiles){

                    ExtendedItem[] items = workspace.getExtendedItems(file.getPath(), DeletedState.ANY,
                            ItemType.ANY);
                    if (items != null && items.length == 1){
                        result.put(file, items[0]);
                    } else {
                        result.put(file, null);
                    }

                    currentItem++;
                    if (currentItem < totalItems){
                        double fraction = (double)currentItem / (double)totalItems;
                        indicator.setFraction(fraction);
                    }
                }
                indicator.stop();
            }
        };
        ProgressManager.getInstance().run(task);

        return result;
    }

//    public static Project getProjectFromFile(VirtualFile file){
//        log.warn("this is a very expensive method to call, you should looking into a better way to get the current project");
//
//        Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
//        for (int i = 0; i < openProjects.length; i++){
//            ProjectRootManager  rootManager = ProjectRootManager.getInstance(openProjects[i]);
//            if (rootManager.getFileIndex().getContentRootForFile(file) != null)
//                return openProjects[i];
//        }
//        throw new RuntimeException("Failed to locate project for file [" + file.getPath() +"]");
//        //return null;
//    }

    public static WorkspaceInfo findWorkspace(FilePath localPath, boolean considerChildMappings, Project project){
        Workstation workstation = Workstation.getCurrent(IdeaPersistenceStoreProvider.INSTANCE);
        int checkCount =0;
        recheck: {
            WorkspaceInfo[] workspaces = workstation.getAllLocalWorkspaceInfo();
            for (int i = 0; i < workspaces.length; i++) {
                WorkspaceInfo workspaceInfo = workspaces[i];
                String[] paths = workspaceInfo.getMappedPaths();
                for (int j = 0; j < paths.length; j++) {
                    FilePath workingFolder = VcsUtil.getFilePath(paths[j], true);
                    if (localPath.isUnder(workingFolder, false) ||
                            (considerChildMappings && localPath.isUnder(workingFolder, false))) {
                        return workspaceInfo;
                    }
                }
            }
        }
        return null;
    }

    public static WorkspaceInfo findWorkspace(VirtualFile localFile, boolean considerChildMappings, Project project) {
        return findWorkspace(getFilePath(localFile), considerChildMappings, project);
    }


    public static boolean isAncestor(@NotNull VirtualFile ancestor, @NotNull VirtualFile file, boolean strict){
        return !ThreeState.NO.equals(isAncestorThreeState(ancestor.getPath(), file.getPath(), strict));
    }

    public static ThreeState isAncestorThreeState(@NotNull String ancestor, @NotNull String file, boolean strict){
        String ancestorPath = FileUtil.toCanonicalPath(ancestor);
        String filePath = FileUtil.toCanonicalPath(file);

        if (ancestorPath == null || filePath == null)
            return ThreeState.NO;
        return startsWith(filePath, ancestorPath, strict, SystemInfo.isFileSystemCaseSensitive, true);
    }

    public static List<VirtualFile> recursivelyGetFilesAndFolders(Project project, VirtualFile baseFolder){
        return recursivelyGetFilesAndFolders(project, baseFolder, true);
    }

    public static List<VirtualFile> recursivelyGetFilesAndFolders(Project project, VirtualFile baseFolder, boolean forIgnored){
        Check.notNull(baseFolder, "baseFolder");
        Check.isTrue(baseFolder.isDirectory() && baseFolder.exists(), "baseFolder must be a directory and exist.");

        List<VirtualFile> files = new ArrayList<VirtualFile>();
        VirtualFile[] subFiles = baseFolder.getChildren();
        for(int i = 0; i < subFiles.length; i++){
            if (forIgnored &&
                    !TFSVcs.getInstance(project).isIgnoredFile(subFiles[i])) {
                files.add(subFiles[i]);
                if (subFiles[i].isDirectory()) {
                    files.addAll(recursivelyGetFilesAndFolders(project, subFiles[i], forIgnored));
                }
            } else if(!forIgnored){
                files.add(subFiles[i]);
                if (subFiles[i].isDirectory()) {
                    files.addAll(recursivelyGetFilesAndFolders(project, subFiles[i], forIgnored));
                }
            }
        }
        return files;
    }

    /**
     * @return ThreeState.YES if same path or immediate parent
     */
    private static ThreeState startsWith(@NotNull String path, @NotNull String start, boolean strict, boolean caseSensitive,
                                         boolean checkImmediateParent) {
        final int length1 = path.length();
        final int length2 = start.length();
        if (length2 == 0) return length1 == 0 ? ThreeState.YES : ThreeState.UNSURE;
        if (length2 > length1) return ThreeState.NO;
        if (!path.regionMatches(!caseSensitive, 0, start, 0, length2)) return ThreeState.NO;
        if (length1 == length2) {
            return strict ? ThreeState.NO : ThreeState.YES;
        }
        char last2 = start.charAt(length2 - 1);
        char next1;
        int slashOrSeparatorIdx = length2;
        if (last2 == '/' || last2 == File.separatorChar) {
            slashOrSeparatorIdx = length2 - 1;
        }
        next1 = path.charAt(slashOrSeparatorIdx);
        if (next1 == '/' || next1 == File.separatorChar) {
            if (! checkImmediateParent) return ThreeState.YES;

            if (slashOrSeparatorIdx == length1 - 1) return ThreeState.YES;
            int idxNext = path.indexOf(next1, slashOrSeparatorIdx + 1);
            idxNext = idxNext == -1 ? path.indexOf(next1 == '/' ? '\\' : '/', slashOrSeparatorIdx + 1) : idxNext;
            return idxNext == -1 ? ThreeState.YES : ThreeState.UNSURE;
        }
        else {
            return ThreeState.NO;
        }
    }

    public static Map<FilePath, ExtendedItem> getFileExtendedItems(Project project, Workspace workspace,
                                                                   List<FilePath> files, DeletedState deletedState,
                                                                   GetItemsOptions getItemsOptions, boolean recursive){
        Map<FilePath, ExtendedItem> filePathExtendedItemMap = new HashMap<>();
        ItemSpec[] itemSpecs = getItemSpecs(project, workspace, files, recursive);
        ExtendedItem[][] extendedItems = workspace.getExtendedItems(itemSpecs, deletedState, ItemType.ANY, getItemsOptions);
        if (extendedItems.length >= 1){
            for(int count = 0; count < extendedItems.length; count++){
                for(int i = 0; i < extendedItems[count].length; i++){
                    String localPath = extendedItems[count][i].getLocalItem();
                    boolean isFolder = extendedItems[count][i].getItemType() == ItemType.FOLDER;
                    filePathExtendedItemMap.put(getFilePath(localPath, isFolder), extendedItems[count][i]);
                }
            }

        }
        for(FilePath file : files){
            if (!filePathExtendedItemMap.containsKey(file))
                filePathExtendedItemMap.put(file, null);
        }
        return filePathExtendedItemMap;
    }

    public static Map<FilePath, ExtendedItem> getFileExtendedItems(Project project, Workspace workspace,
                                                                   List<FilePath> files, DeletedState deletedState,
                                                                   GetItemsOptions getOptions){
        return getFileExtendedItems(project, workspace, files, deletedState, getOptions, false);
    }

    public static Map<FilePath, ExtendedItem> getFileExtendedItems(Project project, Workspace workspace,
                                                                   Collection<VirtualFile> files, DeletedState deletedState,
                                                                   GetItemsOptions getOptions){
        return getFileExtendedItems(project, workspace, getFilePaths(files), deletedState, getOptions);

    }


//    private List<String> findServerPathsByLocalPath(Workspace workspace, FilePath localPath,
//                                                    boolean considerChildMappings, Project project){
//        Check.notNull(workspace, "workspace");
//        Check.notNull(localPath, "localPath");
//        FilePath localPathOnLocalFileSystem = VcsUtil.getFilePath(localPath.getPath(), localPath.isDirectory());
//        WorkingFolder parentMapping = workspace.getClosestMappingForLocalPath(localPathOnLocalFileSystem.getPath());
//        if (parentMapping != null){
//            //TODO try to determine the ServerPath using the parentMapping with the file path..
//        }
//        if (considerChildMappings){
//
//        }
//
//    }
}
